<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<meta http-equiv="pragma" content="no-cache" />
<html  xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
	<title>数据字典配置</title>
	<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
	<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
	<script src="js/json2.js" type="text/javascript"></script>
	<script type="text/javascript">
	
	/* 
	定义 全局变量 saveFlag ， 用来标识当前的保存操作是新增还是编辑
	*/
	var saveFlag = "";
	/*
	定义全局变量oldCode ， 表示被修改的数据行
	*/
	var oldCode = "";
	/*
	定义全局变量oldCodeType ， 表示被修改的数据行
	*/
	var oldCodeType = "";
	//自定义map功能
	function Map(){
	  this.elements = new Array();
	   //获取MAP元素个数
	   this.size = function() {         
	       return this.elements.length;
	   };
	   //判断MAP是否为空
	   this.isEmpty = function() {
	       return (this.elements.length < 1);
	   };
	   //删除MAP所有元素
	   this.clear = function() {
	       this.elements = new Array();
	   };
	   //向MAP中增加元素（key, value)
	   this.put = function(_key, _value) {
	       if(this.containsKey(_key)){
	        this.remove(_key);
	        this.elements.push( {
	           key : _key,
	           value : _value
	        });
	       }else{
	        this.elements.push( {
	           key : _key,
	           value : _value
	        });
	       }  
	   };
	   //删除指定KEY的元素，成功返回True，失败返回False
	   this.remove = function(_key) {
	       var bln = false;
	       try {
	           for (var i = 0; i < this.elements.length; i++) {
	               if (this.elements[i].key == _key) {
	                   this.elements.splice(i, 1);
	                   return true;
	               }
	           }
	       } catch (e) {
	           bln = false;
	       }
	       return bln;
	   };
	   //获取指定KEY的元素值VALUE，失败返回NULL
	   this.get = function(_key) {
	       try {
	           for (var i = 0; i < this.elements.length; i++) {
	               if (this.elements[i].key == _key) {
	                   return this.elements[i].value;
	               }
	           }
	       } catch (e) {
	           return false;
	       }
	       return false;
	   };
	   //判断MAP中是否含有指定KEY的元素
	   this.containsKey = function(_key) {
	       var bln = false;
	       try {
	           for (var i = 0; i < this.elements.length; i++) {
	               if (this.elements[i].key == _key) {
	                   bln = true;
	               }
	           }
	       } catch (e) {
	           bln = false;
	       }
	       return bln;
	   };
	  //获取map的所有values
	  this.values = function() {
	       var arr = new Array();
	       for (var i = 0; i < this.elements.length; i++) {
	           arr.push(this.elements[i].value);
	       }
	       return arr;
	   };
	  //获取map的所有keys
	  this.keys= function() {
	       var arr = new Array();
	       for (var i = 0; i < this.elements.length; i++) {
	           arr.push(this.elements[i].key);
	       }
	       return arr;
	   };
	   //获取数组
	   this.getArray= function(){
	   	var arr = new Array();
	   	for (var i = 0; i < this.elements.length; i++) {
	           arr.push({
		            key : this.elements[i].key,
		            value : this.elements[i].value
		         });
	       }
	       return arr;
	   };
	}
//********************************************	
	$(document).ready(function() {
		queryDictList(1);
	})
	//为查询数据字典列表
	function queryDictList(pageIndex){
		var codeName = $.trim($('#codeName').val());
		var codeDesc = $.trim($('#codeDesc').val());
		loadDictList({current:pageIndex,size:10,codeName:codeName,codeDesc:codeDesc});
	}
	//查询数据列表
	function loadDictList(param){
		$.openLoading();
		$.ajax({
				url : "<%=path%>/dictManager/queryDictPageByCriteria?"+new Date().getTime(),
				type : 'POST',
				async : true,	
				dataType:'json',
				data:param,
				success : function(page) {
					$.closeLoading();
					if($.validate(page))return;
					var flag=page.obj 
					
					var lastbutton = "<a href='javascript:void(0)' onClick='editGatewayDict(this);return false'>编辑</a>&nbsp;<a href='javascript:void(0)' onClick='delDict(this);return false'>删除</a>";
					var tableContent = creatTable5("codetype,code,codename,codedesc,status?[{0:'无效'};{1:'有效'}],parentcode,othercode,otherName,othercode2,othername2",page,null,lastbutton)
					var tableObj = $("#gatewayDictTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					 console.log("当前页数：" + param.current); 
					var strPage = creatChannelPage(param.current,6,page.maxPage,"85");
					var pageDIV = $("#txproductpageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
				}
			});
		}
	/* 删除条目 */
	function delDict(obj){
		//确定被编辑的对象行
		var editTr = $(obj).parent('td').parent('tr')[0];
		/* 
		code 与 codeType构成联合主键
		*/
		var codeType = editTr.childNodes[0].innerHTML;
		var code = editTr.childNodes[1].innerHTML;
		//弹出确认窗口
		 $.dialog({
				type: "warn",
				content: "是否确认删除此条字典信息？",
				onOk: function() {
					delGatewayDict({codeType:codeType,code:code});
				}
			});
		
		
	}
	
	function delGatewayDict(param){
		
		$.openLoading();
		$.ajax({
			url : "dictManager/delDict",
			type : 'POST',
			async : true,
			dataType:'json',
			data:param,
			success : function(obj) {	
				$.closeLoading();
				//对返回信息进行校验 ， 若出错直接报错
				if($.validate(obj))
					return;
				queryDictList(1);
				closeEditDictDiv();
			}
		});
		
	}
	
	/* 打开编辑窗体 */
	function editGatewayDict(obj){
		//确定被编辑的对象行
		var editTr = $(obj).parent('td').parent('tr')[0];
		//获取改行数据并回写至页面上
		oldCodeType = editTr.childNodes[0].innerHTML;
		oldCode = editTr.childNodes[1].innerHTML;
		var codeName = editTr.childNodes[2].innerHTML;
		var codeDesc = editTr.childNodes[3].innerHTML;
		var status = editTr.childNodes[4].innerHTML;
		var otherCode = editTr.childNodes[6].innerHTML;
		var otherName = editTr.childNodes[7].innerHTML;
		var parentCode = editTr.childNodes[5].innerHTML;
		var otherCode2 = editTr.childNodes[8].innerHTML;
		var code2Name = editTr.childNodes[9].innerHTML;
		
		$("#eCodeType").val(oldCodeType);
		$("#eCode").val(oldCode);
		$("#eCodeName").val(codeName);
		$("#eCodeDesc").val(codeDesc);
		$("#eStatus").val(status);
		$("#eOtherCode").val(otherCode);
		$("#eOtherName").val(otherName);
		$("#eParentCode").val(parentCode);
		$("#eOtherCode2").val(otherCode2);
		$("#eCode2Name").val(code2Name);
		
		//显示编辑窗体
		$("#editDictDiv").OpenDiv();

		saveFlag = "update";
	}
	function addDict(){
		vreset();
		$("#editDictDiv").OpenDiv();
		saveFlag = "insert";
	}
	
	/* 单击保存 ，将该条字典信息更新或新增 */
	function saveEditDict(){
		var editDIV = $("#editDictDiv");
		//取得编辑窗体的内容
		var codeType = $("#eCodeType").val();
		var code = $("#eCode").val();
		var codeDesc = $("#eCodeDesc").val();
		var status = $("#eStatus").val();
		var otherCode = $("#eOtherCode").val();
		var otherName = $("#eOtherName").val();
		var codeName = $("#eCodeName").val();
		var parentCode = $("#eParentCode").val();
		var otherCode2 = $("#eOtherCode2").val();
		var code2Name = $("#eCode2Name").val();
		if(codeType==""){
	    	$.message("error","请输入编码类型");
	    	$prodType.focus();
	    	return false;
	    }
		if(code==""){
	    	$.message("error","请输入编码");
	    	$prodType.focus();
	    	return false;
	    }
		
		if("update" == saveFlag){
			 
				
						updateDictInfo({codeType:codeType,code:code,codeName:codeName,codeDesc:codeDesc,status:status,otherCode:otherCode,otherName:otherName,parentCode:parentCode,otherCode2:otherCode2,code2Name:code2Name,oldCode:oldCode,oldCodeType:oldCodeType});
					}
				
		else if("insert" == saveFlag){
				
						insertDictInfo({codeType:codeType,code:code,codeName:codeName,codeDesc:codeDesc,status:status,otherCode:otherCode,otherName:otherName,parentCode:parentCode,otherCode2:otherCode2,code2Name:code2Name});
			
					}
	}
	
	//编辑字典ajax
	function updateDictInfo(param){
		$.openLoading();
		$.ajax({
			url : "dictManager/updateDict",
			type : 'POST',
			async : true,
			dataType:'json',
			data:param,
			success : function(obj) {	
				$.closeLoading();
				//对返回信息进行校验 ， 若出错直接报错
				if($.validate(obj))
					return;
				queryDictList(1);
				closeEditDictDiv();
			}
		});
	}
	//新增字典ajax
	function insertDictInfo(param){
		$.openLoading();
		$.ajax({
			url : "dictManager/insertDict",
			type : 'POST',
			async : true,
			dataType:'json',
			data:param,
			success : function(obj) {
				$.closeLoading();
				//对返回信息进行校验 ， 若出错直接报错
				if($.validate(obj))
					return;
				queryDictList(1);
				closeEditDictDiv();
			}
		});
	}
	
	
	
	//关闭窗体方法:
		function closeEditDictDiv(){
		$("#editDictDiv").CloseDiv();
	}
	//重置方法：
		function vreset(){
			$("#eCodeType").val("");
			$("#eCode").val("");
			$("#eCodeName").val("");
			$("#eCodeDesc").val("");
			$("#eStatus").val("");
			$("#eOtherCode").val("");
			$("#eOtherName").val("");
			$("#eParentCode").val("");
			$("#eOtherCode2").val("");
			$("#eCode2Name").val("");
			$("#codeName").val("");
			$("#codeDesc").val("");
	}
	</script>
</head>
<body >
	<div class="current">
           <table class="current_table_1">
              <tbody>
                <tr class="f2">
                  <td>
                    <img src="./images/current_1.jpg">
                  </td>
                  <td class="current_table_1_td">
                    <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                      <span style=" color:#136bab; ">系统管理
                      <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>数据字典维护
                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
           </tbody>
         </table>
      </div>
		
		<table class="table_02" id="table">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td width="20%" height="30">编码名称：
								<input name="txt3" id="codeName" type="text" class="input_text" maxlength="30" value="">
							</td>
							<td width="20%" height="30">编码描述：
								<input name="txt3" id="codeDesc" type="text" class="input_text" maxlength="100" value="">
							</td>
							<td style="text-align: center;" colspan="5" width="10%" height="30">
								<input type="button" class="input_button_1" id="searchBtn" value="查询" onClick="queryDictList(1)" />&nbsp;
							    <input type="button" class="input_button_1" id="searchBtn" value="重置" onClick="vreset()" />
								<input type="button" class="input_button_1" id="searchBtn" value="新增" onClick="addDict()" />
							</td>
						</tr>
						<tr height="30px">
						</tr> 
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="gatewayDictTable" class="content_table_1">
						<thead>
							<tr class="f1">
								<th style="width:7%">编码类型</th>
								<th style="width:7%">编码</th>
								<th style="width:7%">编码名称</th>
								<th style="width:7%">编码描述</th>
								<th style="width:3%">状态</th>
								<th style="width:8%">父编码</th>
								<th style="width:8%">拓展字段</th>
								<th style="width:8%">拓展名称</th>
								<th style="width:8%">拓展字段2</th>
								<th style="width:8%">拓展名称2</th>
								<th style="width:6%">操作</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="txproductpageDIV" class="page"></div>
				</td>
			</tr>
		</table>
		
		<!-- 编辑DIV 默认隐藏  -->
		
		<div id="editDictDiv"  style="display:none;overflow-y:auto; width:60%">
			<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="/manager/images/closedown.gif" alt="关闭"  onclick="closeEditDictDiv()"/></td>
						</tr>
					</table>
			</div>
			<!-- 修改id 名 -->
			<table class="table_02" id="addtempletTable" align="center">
				<tbody>
					<tr>
						<td>
							<table id="coverageTable"  class="content_table_1" style="height:120px;">
								
								<tbody>
									<tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">编码类型：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eCodeType" class="input_text" style="width: 250px"><span class="red">*</span></td>
					                </tr>
					                <tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">编码：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eCode" class="input_text" style="width: 250px"><span class="red">*</span></td>
					                </tr>
					                <tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">编码名称：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eCodeName" class="input_text" style="width: 250px"></td>
					                </tr>
					                 <tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">编码描述：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eCodeDesc" class="input_text" style="width: 250px"></td>
					                </tr>
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">状态：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><select name="eprodType" id="eStatus" class="select_1" style="visibility: visible;width: 250px;">
 					                  <option value="0">无效</option>
	                  				  <option value="1">有效</option>
					                  </select></td>
					                </tr>
					                <tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">父编码：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eParentCode" class="input_text" style="width: 250px"></td>
					                </tr>
					                <tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">拓展字段：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eOtherCode" class="input_text" style="width: 250px"></td>
					                </tr><tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">拓展名称：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eOtherName" class="input_text" style="width: 250px"></td>
					                </tr><tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">拓展字段2：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eOtherCode2" class="input_text" style="width: 250px"></td>
					                </tr><tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">拓展名称2：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eCode2Name" class="input_text" style="width: 250px"></td>
					                </tr>
								</tbody>
							</table>
							
						</td>
					</tr>
				</tbody>
			</table>
			<div align="center">
			   <input class="input_button_3" name="" type="button" onclick="saveEditDict()" value="保存">&nbsp;&nbsp;
	           <input class="input_button_3" name="" type="button" onclick="closeEditDictDiv()" value="取消">
			</div>
	</div>
		
		<div id="Loading" style="display:none" align="center">
			<img src="./images/loading.gif" />
		</div>
	
</body>
</html>